﻿using System;
using 管道.Model;
using 管道.Pipeline管道基类;
using 管道.房源成交管道事件;

namespace 管道
{
    public class 管道
    {
        /// 说明
        /// 一个业务进行了状态的扭转，需要修改围绕着该业务上下的所有内容
        /// 



        public static DemoResponseDto Demo(DemoRequestDto req)
        {
            #region 验证
            if (req.propertyKeyId == null ||
                req.propertyKeyId.Equals(Guid.Empty) ||
                (int)req.transactionType < 0 ||
                req.stageType < 0 ||
                string.IsNullOrEmpty(req.empNo))
            {
                return new DemoResponseDto("房源交易完成,参数错误");
            }
            PropertyPipelineeContextModel model = new PropertyPipelineeContextModel();
            if (model == null)
            {
                return new DemoResponseDto("房源交易完成,没有找到房源对象");
            }
            #endregion

            DemoResponseDto resp = new DemoResponseDto();
            //创建管道事件
            IPipeline pipeline = new Pipeline();
            //注册房源处理管道事件
            pipeline.AddPipelineHandle(new PropertyPipelineHandler());
            //注册房源业主处理管道事件
            pipeline.AddPipelineHandle(new PropertyTrustorPipelineHandler());

            //成交报告审批
            if (req.stageType == 1 && req.transactionType == TrustTypeEnum.RENT)
            {
                //注册房源归档管道事件
                pipeline.AddPipelineHandle(new PropertyTransactionTradeCompletePipelineHandler());
                //注册下架房源管道事件
                pipeline.AddPipelineHandle(new PropertyPuOffPipelineHandler());
                //注册删除房源委托备案管道事件
                pipeline.AddPipelineHandle(new PropertyDeleteTrustPipelineHandler());
                //
                if (model.Property.PropertyTrust == TrustTypeEnum.RENT)
                {

                }
                if (model.Property.PropertyTrust == TrustTypeEnum.BOTH)
                {

                }
            }
            //过户审批通过
            if (req.stageType == 2)
            {

            }

            pipeline.Push(model);

            return resp;
        }



    }



}
